from google.appengine.tools import bulkloader
import datetime
import logging
log = logging.getLogger("dbloader")

from google.appengine.ext import db

import appdb

class ScanSiteLoader(bulkloader.Loader):
  def __init__(self):
    bulkloader.Loader.__init__(self, "ScanSite",
                               [("url", str),
                                ])

  def generate_key(self, i, values):
    return appdb.GenURLKeyName("Site", values[0])
  
class ScanTableLoader(bulkloader.Loader):
  def __init__(self):
    bulkloader.Loader.__init__(self, "ScanTable",
                               [("url", str),
                                ("count", int),
                                ("date", lambda x: datetime.datetime.strptime(x, "%Y-%m-%d")),
                                ("fmt", str),
                                ("unit", lambda x: x.decode("utf-8")),
                                ("tags", lambda x: x.decode("utf-8")),
                                ])

  def generate_key(self, i, values):
    return appdb.GenURLKeyName("Table", values[0])


loaders = [ScanSiteLoader, ScanTableLoader]
